import { Component, OnInit, Output } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { EventEmitter } from '@angular/core';
import { technicalList } from '../Config';

@Component({
  selector: 'app-recommend-record',
  templateUrl: './recommend-record.component.html',
  styleUrls: ['./recommend-record.component.scss']
})
export class RecommendRecordComponent implements OnInit {

  @Output() assessment = new EventEmitter<any>()
  constructor(
    private message: NzMessageService
  ) { }

  public cardData01 = technicalList[0]
  public cardData02 = technicalList[1]
  public cardData03: any = technicalList[2]

  public cardValue01 = this.cardData01.list[1].value
  public cardValue02 = this.cardData02.list[0].value
  public cardValue03 = null

  public addedCombinations = []

  ngOnInit() {
  }

  addTecCombination() {
    let coms = [this.cardValue01, this.cardValue02];
    if (this.cardValue03) {
      coms.push(this.cardValue03)
    }

    let isAdded = this.addedCombinations.find((item: Array<any>) => item.join() == coms.join())
    if (isAdded) {
      this.message.warning('该技术方案组合已添加!')
      return
    }
    this.addedCombinations.push(coms)
  }

  exeAssessment() {
    if (this.addedCombinations.length !== 4) {
      this.message.warning('请选择四组技术组合!')
      return
    }
    this.assessment.emit(this.addedCombinations)
  }

  remove(index) {
    this.addedCombinations.splice(index, 1)
  }

  onCheckboxChange(item) {
    this.cardData03.list.forEach(element => {
      if (element.value != item.value) {
        element.checked = false
      }
    });

    this.cardValue03 = item.checked ? item.value : ''
  }
}
